﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.Integration;
using DAWSharp.FileFormats.WavFile;

namespace DAWSharp.UI.WinFormsControls
{
    public partial class WPFWaveDisplayContainer : UserControl
    {
        private WavFile _wavFile;
        public Int64 _leftMostSample { get; set; }
        public Int64 _rightMostSample;
        public Int64 _samplesPerPixel;

        public WPFWaveDisplayContainer(string WaveFilePath, Int64 leftMostSample, Int64 rightMostSample, Int64 samplesPerPixel)
        {
            InitializeComponent();

            _leftMostSample = leftMostSample;
            _rightMostSample = rightMostSample;
            _samplesPerPixel = samplesPerPixel;

            _wavFile = new WavFile();
            _wavFile.OpenWavFile(WaveFilePath);

            AddWaveDisplays();
        }

        public void LoadWavFile(string FilePath)
        {
            _wavFile = new WavFile();
            _wavFile.OpenWavFile(FilePath);

            AddWaveDisplays();
        }

        private void AddWaveDisplays()
        {
            if (_wavFile.GetNumberOfChannels() == 1)
            {
                ElementHost hostMono = new ElementHost()
                {
                    Location = new Point(0, 0),
                    AutoSize = true
                };
                hostMono.Child = new WPFControls.MonoWaveDisplay(_wavFile, WPFControls.MonoWaveDisplay.Channel.Mono, false, this.Height, this.Width);
                this.Controls.Add(hostMono);
            }
            else
            {
                ElementHost hostLeft = new ElementHost()
                {
                    Location = new Point(0, 0),
                    AutoSize = true
                };
                hostLeft.Child = new WPFControls.MonoWaveDisplay(_wavFile, WPFControls.MonoWaveDisplay.Channel.Left, false, this.Height / 2, this.Width);
                this.Controls.Add(hostLeft);

                ElementHost hostRight = new ElementHost()
                {
                    Location = new Point(0, this.Height / 2),
                    AutoSize = true
                };
                hostRight.Child = new WPFControls.MonoWaveDisplay(_wavFile, WPFControls.MonoWaveDisplay.Channel.Right, false, this.Height / 2, this.Width);
                this.Controls.Add(hostRight);
            }
        }
    }
}
